<!--#include file="p1.asp" -->
<%
on error resume next
m1()
m3()
Function m3()
	dim conn2
	'追风透骨数据库'
	Easp.Db.SetConnection "conn2", "ACCESS", "/dzps/dbs/" & val("fn") &".mdb", ""
	Set conn2 =  Easp.Db.GetConnection("conn2")

	dim rs,sql,primarykey,bl,field0,i,ret
	Set rs = Easp.Db.Sel("select * from [bi0] order by id ")'where tn={tn}
	primarykey="id"
	dim line,modret,arr(15)
	sql = ""

	for i=0 to 10 
		arr(i)=cstr(i)
	next 

line=0
modret=0
Do While Not rs.EOF
	line=line+1
	modret = line \ 248
	if arr(modret) = cstr(modret) then 
		sql = "CREATE TABLE ["& easp.var("tn")  & cstr(modret) &"] ("
		arr(modret)= sql
		if modret > 0 then
			arr(modret)=arr(modret) & "ID AUTOINCREMENT PRIMARY KEY"
			arr(modret)=arr(modret) & ",[NUMB] varchar(30),"
		end if

	end if

	field0=trim(rs("fld"))
	if field0="ID" then
		sql=sql& " ID AUTOINCREMENT PRIMARY KEY,"
		arr(modret)=arr(modret)& " ID AUTOINCREMENT PRIMARY KEY,"
	end if



	if (instr(field0,"blank")>0 or (field0="ID")) then
		ret= easp.db.upd("bi0","tn=tn+'"&cstr(modret)+"'","fld='"& field0 &"'")
	else
		ret= easp.db.upd("bi0","tn=tn+'"&cstr(modret)+"'","fld='"& field0 &"'")
		arr(modret) = arr(modret) & "[" & field0 & "] " & " varchar(160)"
		arr(modret) = arr(modret) & ","
	end if
    rs.MoveNext
Loop
	
for i= 0 to ubound(arr)	
	if len(arr(i))>10 then
		sql=arr(i)
		sql=left(sql,len(sql)-1)
		' sql=sql&" primary key (["&primarykey&"]) "
		sql = sql & ")"
		easp.wrn sql
		ret = Easp.Db.Execute(conn2, sql)		
		' conn.execute (sql)
		
		sql="Create INDEX idx_" & cstr(i)  &  " ON " & val("tn") & cstr(i) & " (NUMB)"'UNIQUE
		ret = Easp.Db.Execute(conn2, sql)		
		
	end if
next
End Function

Function m1()
dim fs,f,txt,mystr,i
dim head,tail,tail1,tail0,regEx,sql
dim line,ret,blank

set fs=Server.CreateObject("Scripting.FileSystemObject") 
Set f=fs.OpenTextFile(Server.MapPath("upload\" & val(qes) &), 1)
ret= Easp.Db.Del("[bi0]", "1=1")
echo ret
line=0
blank=0
do while f.AtEndOfStream = false
	line=line+1
	txt=f.ReadLine
	if line=1 then
		easp.var("tn")=txt
		Easp.Db.Del "bi0", "tn={tn}"
	end if
    head=""
	tail=""

	easp.var("fld")=""
	easp.var("colName")=""
	easp.var("mm1")=""
	easp.var("regu1")=""
	
	if RegExpTest2("#+\.?#*", txt)<>"" then
		easp.wrn txt
		regEx="#+\.?#*"

		mystr=split(RegExpTest2(regEx, txt),"|") 
		tail= mid(txt,cint(mystr(0)))
		head=mid(txt,1,cint(mystr(0))-1)
		m2(head)
		tail0=mystr(1)
		tail1=replace(tail,tail0,"")

		easp.var("mm1")=tail1
		easp.var("regu1")=tail0
		sql=cr("bi0","fld,colName,mm1,regu1,tn") 
		easp.wrn Easp.Db.ToSql(sql)
	elseif RegExpTest2("\_+", txt)<>"" then
		easp.wrn txt
		regEx="\_+"

		mystr=split(RegExpTest2(regEx, txt),"|") 
		tail= mid(txt,cint(mystr(0)))
		head=mid(txt,1,cint(mystr(0))-1)
		m2(head)
		tail0=mystr(1)
		tail1=trim(ReplaceTest(tail,regEx,""))

		easp.var("mm1")=tail1
		easp.var("regu1")=tail0
		sql=cr("bi0","fld,colName,mm1,regu1,tn") 
		easp.wrn Easp.Db.ToSql(sql)
	elseif RegExpTest2("<\S+>", txt)<>"" then
		easp.wrn txt
		regEx="<\S+>"

		mystr=split(RegExpTest2(regEx, txt),"|") 
		tail= mid(txt,cint(mystr(0)))
		head=mid(txt,1,cint(mystr(0))-1)
		easp.wrn "<-" & head 
		m2(head)
		tail0=mystr(1)
		tail1=trim(ReplaceTest(tail,regEx,""))
	
		easp.var("mm1")=tail1
		easp.var("regu1")=tail0
		sql=cr("bi0","fld,colName,mm1,regu1,tn") 
		easp.wrn Easp.Db.ToSql(sql)
	else
		blank=blank+1
		if txt="" then
			easp.var("fld")="blank" & cstr(blank)
			sql=cr("bi0","fld,colName,mm1,regu1,tn") 
			' easp.wrn Easp.Db.ToSql(sql)
		else
			easp.var("fld")="blank"& cstr(blank)
			easp.var("mm1")=txt
			sql=cr("bi0","fld,colName,mm1,regu1,tn") 
			easp.wrn Easp.Db.ToSql(sql)
		end if
	end if
	Easp.Db.Exec(sql)
loop
f.Close
Set f=Nothing
Set fs=Nothing
End Function

Function m2(strng) 
	dim temp,head,tail
	temp=split(RegExpTest2("\s+",strng),"|") 
	head=mid(strng,1,cint(temp(0))+1)
	tail=mid(strng,cint(temp(0))+1)
	easp.var("fld")=head
	easp.var("colName")=tail
End Function
%>